package com.quanjiaolian.userinfo.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.quanjiaolian.tools.ResponseToJson;
import com.quanjiaolian.userinfo.service.UserInfoService;
import com.quanjiaolian.userinfo.serviceimpl.UserInfoServiceImpl;
/**
 * 处理用户密码修改请求
 * @author Herson_Li
 *
 */
@SuppressWarnings("serial")
public class UpdateUserPasswd extends HttpServlet {

	/**
	 * 声明Log4j变量
	 */
	public static ResourceBundle resourceBundle = null;
	static Logger logger = Logger.getLogger(UpdateUserPasswd.class.getName());
	UserInfoService uis = new UserInfoServiceImpl(); 
	Map<String,Object> resultMap = new HashMap<String,Object>();
	/**
	 * 更新用户密码
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try{
			String user_id = request.getParameter("user_id");
			String user_type = request.getParameter("user_type");
			String old_passwd = request.getParameter("old_passwd");
			String new_passwd = request.getParameter("new_passwd");
			int i = uis.checkPasswd(user_id, user_type, old_passwd);
			if(i>0){
				int j = uis.updatePasswd(user_id, user_type, new_passwd);
				if(j>0){
					resultMap.put("result","OK");
				}else{
					resultMap.put("result","Failed");
				}
			}else{
				resultMap.put("result","old passwd error");
			}
		}catch (Exception e) {
			resultMap.put("result","Error");
		}
		ResponseToJson.responseOutWithJson(response,resultMap);
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

			this.doGet(request, response);
	}

}
